<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%
    String path = request.getContextPath();
%>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>欢迎登录网关监控平台</title>
    <%@ include file="/WEB-INF/jsp/common/common.jsp" %>
</head>
<body style="padding:10px">
	<form action="/test" method="post">
	<br/>
	<input type="button" value="清除session" onclick="clearSession()"/>
	<hr/>
		姓名:<input type="text" name="name" id="name"/><br/>
		<input type="button" value="Ajax测试" onclick="testAjax()"/><br/>
		<input type="button" value="Ajax测试2" onclick="testAjax2()"/><br/>
	</form>
</body>
</html>

<script type="text/javascript">
	function testAjax(){
		$.ajax({
			url : "<%=path%>/testAjax",
			type : 'POST',
			async : true,
			cache:false,
			data:{
				name:$("#name").val()
			},
			dataType:'json',
			success : function(data) {
				if(data.result == "fail"){//错误
					alert("操作执行错误："+data.message);
				}else{//业务处理
					alert(data.userName);
				}
			}
		});
	}
	
	function testAjax2(){
		$.ajax({
			url : "<%=path%>/testAjax2",
			type : 'POST',
			async : true,
			cache:false,
			data:{
				name:$("#name").val()
			},
			//accepts:'application/json',
			//contentType:"application/x-www-form-urlencoded;charset=UTF-8",
			dataType:"json",
			success : function(result) {
				if(result && result.result == "fail"){//错误
					alert("操作执行错误："+result.message);
				}else{//业务处理
					alert(result.message);
				}
			},
			error:function (XMLHttpRequest, textStatus, errorThrown) {
			   alert(errorThrown);
			}
		});
	}
	
	function clearSession(){
		$.ajax({
			url : "<%=path%>/clearSession",
			type : 'POST',
			async : true,
			dataType:'json',
			success : function(data) {
				if(data.result == "fail"){//错误
					alert("操作执行错误："+data.message);
				}else{//业务处理
					alert(data);
				}
			}
		});
	}
	
</script>